# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=desync
pkgver=0.9.3
pkgrel=1
pkgdesc="Alternative casync implementation"
arch=(loong64 x86_64)
url="https://github.com/folbricht/desync"
license=(BSD)
depends=(glibc)
makedepends=(go)
# NOTE: debug packages for go packages are not yet supported
# options=(debug)
source=($pkgname-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz)
sha512sums=('ffd97773a51c420c6470ee26c1c93308d625079b8fa598cc8d9558c050a3a86e6096dff1f8b9cbc3413fa70048ba4445a34fd238ab4737e720470572430b43a6')
b2sums=('a5d898eadae0b3d42af61fa545b0c556dd5ab90127a4132a23a6feb15217b11ec3385040f40c35e6223eff52f58a0bdb2ec66f165e45915c80674db47fc64003')

build() {
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw"

  cd $pkgname-$pkgver
  go build -o $pkgname ./cmd/$pkgname
}

check() {
  cd $pkgname-$pkgver
  go test ./cmd/$pkgname
}

package() {
  cd $pkgname-$pkgver
  install -vDm 755 $pkgname -t "$pkgdir/usr/bin/"
  install -vDm 644 README.md -t "$pkgdir/usr/share/doc/$pkgname/"
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}
